package ge;

import java.util.Arrays;
import java.util.Iterator;

public class BitsIterator implements Iterator<Boolean[]> {
	private Boolean[] _bits = null;
	private int _last_index = 0;
	private int _pos = 0;
	private int _num_bits = 0;

	public BitsIterator(int num_bits) {
		_bits = new Boolean[num_bits];
		Arrays.fill(_bits, false);
		_num_bits  = num_bits;
		_last_index = num_bits - 1;
	}

	public boolean hasNext() {
		return _pos < _num_bits;
	}

	public Boolean[] next() {
		_pos ++;
		boolean carry = true;
		for (int j = _last_index; j >= 0 && carry; j--) {

			if (carry) {
				carry = _bits[j];
				_bits[j] = !_bits[j];
			}
		}

		return _bits;
	}

	public void remove() {
		// do nothing;
	}
}
